snapshot: Limit cairo nodes to clip region
authorTimm Bäder <mail@baedert.org>
Mon, 19 Mar 2018 17:52:12 +0000 (18:52 +0100)
committerTimm Bäder <mail@baedert.org>
Tue, 20 Mar 2018 08:40:10 +0000 (09:40 +0100)
In certain cases, we might create large cairo nodes, resulting in
surfaces so large, cairo can't handle them. Fix this by limiting the
cairo node to the current clip region.

gtk/gtksnapshot.c

index c9ebf0b5a0dd6b1af6946c4d01ee35525283ff26..420f7b6c87e8e9b1460e3a824fa7e5e14561e6ad 100644 (file)
@@ -1339,6 +1339,20 @@ gtk_snapshot_append_cairo (GtkSnapshot           *snapshot,
   g_return_val_if_fail (bounds != NULL, NULL);
 
   graphene_rect_offset_r (bounds, current_state->translate_x, current_state->translate_y, &real_bounds);
+
+  if (current_state->clip_region)
+    {
+      cairo_rectangle_int_t clip_extents;
+      cairo_region_get_extents (current_state->clip_region, &clip_extents);
+      graphene_rect_intersection (&GRAPHENE_RECT_INIT (
+                                    clip_extents.x,
+                                    clip_extents.y,
+                                    clip_extents.width,
+                                    clip_extents.height
+                                  ),
+                                  &real_bounds, &real_bounds);
+    }
+
   node = gsk_cairo_node_new (&real_bounds);
 
   if (name && snapshot->record_names)